package com.tpc.pictool.utils;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import java.sql.Connection;
import java.sql.SQLException;

public class CodeUtil {
    public static int getAnnexIdCode(Connection connection){
        String sql = "select recnum+1 from syscode where prefix = 'A'";
        QueryRunner queryRunner = new QueryRunner();
        int value = 0;
        try {
            value = (int) queryRunner.query(connection, sql, new ScalarHandler());
            String updateSql = "update syscode set recnum = ? where prefix = 'A'";
            queryRunner.update(connection,updateSql,value);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return value;
    }
}
